﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eis51.CampanyCMS.Business;
using Eis51.CampanyCMS.Business.NewsManager;
using Eis51.CampanyCMS.Model.NewsManager;

using Eis51.CampanyCMS.FrameWork;

using Eis51.CampanyCMS.Model;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.UI.Admin.NewsManager
{
    public partial class NewNewsUpdate : BasePage
    {
         

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lblcid.Text = AppContext.LcidCnName(AppContext.LCID);
                NewstypeBLL.BindDropListTreeType(drList, "");
                drList.Items.Insert(0, new ListItem("请选择", "0"));
            
            }
        }

        private void ShowData()
        {
            News news = NewsBLL.GetnewsByType(AppContext.GetCurrentName(), int.Parse(drList.SelectedValue), AppContext.LCID);
            if (news != null)
            {
                this.txtTitle.Text = news.Title;
                txtContent.Value = news.Content;
                // txtcode.Text = news.Code;
                txtShowDescr.Text = news.Showdescr;
                //  BaseTools.SetListControl(drList, news.Type.ToString());
            }
            else
            {
                this.txtTitle.Text = "";
                txtContent.Value = "";
              
                txtShowDescr.Text = "";
            }
            
        }

        protected void drList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowData();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            News news = NewsBLL.GetnewsByType(AppContext.GetCurrentName(), int.Parse(drList.SelectedValue), AppContext.LCID);
            if (news == null)
            {
                news = new News();
            }
            Newstype newtype = NewstypeBLL.GetInstance().Get(new Newstype.Key(int.Parse(this.drList.SelectedValue)));
           
            news.Code = newtype.Code;
            news.Content = txtContent.Value;
            news.Showdescr = txtShowDescr.Text;
            news.Title = txtTitle.Text;
            news.Type = int.Parse(drList.SelectedValue);
            news.Lasteupdateby = AppContext.GetCurrentName();
            news.Lasteupdatedate = DateTime.Now;
            
            news.IsValid = 1;
            news.Licd = AppContext.LCID;
            if (news.Seqno>0)
            {
                NewsBLL.GetInstance().Update(news);
            }
            else
            {
                news.Createby = AppContext.GetCurrentName();
                news.Createdate = DateTime.Now;
                NewsBLL.GetInstance().Insert(news);
            }

 
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {

        }
    }
}
